package cn.tedu.ivos.approval.caontroller;
import cn.tedu.ivos.approval.pojo.dto.ApplicationQueryParam;
import cn.tedu.ivos.approval.pojo.dto.ApplicationSaveParam;
import cn.tedu.ivos.approval.pojo.vo.ApplicationVO;
import cn.tedu.ivos.approval.service.ApplicationService;
import cn.tedu.ivos.base.handler.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@Api(tags = "申请单管理")
@RequestMapping("/v1/application")
public class ApplicationController {
    @Autowired
    private ApplicationService applicationService;

    @ApiOperation(value = "保存申请单")
    @PostMapping("save")
    public JsonResult saveApplication(ApplicationSaveParam applicationSaveParam) {
        log.debug("保存申请单:applicationSaveParam={}",applicationSaveParam);
        applicationService.save(applicationSaveParam);
        return JsonResult.ok();
    }
@ApiOperation(value = "查询申请单")
    @GetMapping("select")
    public JsonResult select(ApplicationQueryParam applicationQuery){
        log.debug("查询申请单:applicationQuery={}",applicationQuery);
        List<ApplicationVO> list = applicationService.selectApplication(applicationQuery);
        return JsonResult.ok(list);
    }

 @PostMapping("cancel/{id}")
 public JsonResult cancel(@PathVariable Long id){
        log.debug("撤销申请：id={}",id);
        applicationService.cancel(id);
        return JsonResult.ok();
 }

    @PostMapping("distribute/{applicationId}/{vehicleId}")
    public JsonResult distribute(
            @PathVariable Long applicationId,@PathVariable Long vehicleId){
        log.debug("分配车辆:applicationId={},vehicleId={}",applicationId,vehicleId);
        applicationService.distribute(applicationId,vehicleId);
        return JsonResult.ok();
    }

    @PostMapping("back/{applicationId}/{vehicleId}")
    public JsonResult back(
            @PathVariable Long applicationId,@PathVariable Long vehicleId){
        log.debug("归还车辆:applicationId={},vehicleId={}",applicationId,vehicleId);
        applicationService.back(applicationId,vehicleId);
        return JsonResult.ok();
    }
}
